package main

import (
	"fmt"
	"strconv"
)

func sum(t ...int) (res int) {
	for _, v := range t {
		res += v
	}
	return res
}

func sumNum(t ...interface{}) (res float64) {
	for _, tmp := range t {
		switch v := tmp.(type) {
		case int:
			res += float64(v)
		case float64:
			res += v
		case float32:
			res += float64(v)
		}
	}
	return res
}

func sumCase(t ...interface{}) (res float64) {
	for _, tmp := range t {
		switch v := tmp.(type) {
		case int, int8, int16, int32, int64, uint, uint64, float32, float64:
			convertStr := fmt.Sprintf("%v", v)
			convertFloat64, _ := strconv.ParseFloat(convertStr, 64)
			res += convertFloat64
		}
	}
	return res
}

/*
https://golang-minibear2333.github.io/2.func-containers/2-3-%E5%8F%AF%E5%8F%98%E5%8F%82%E6%95%B0/
*/
func main() {

	fmt.Println(">>>>>>>>>>>>>>")

	fmt.Println(sum(1, 2, 3, 4, 5))

	fmt.Println(">>>>>>>>>>>>>>")

	fmt.Println(sumNum(1, 2, "2", "asd", "true", 3, 4, 5))

	fmt.Println(">>>>>>>>>>>>>>")

	fmt.Println(sumCase("1", "true", 1, 2, 3, 4, 5))
}
